<?php

/**
 * Description of b
 * 
 * @author 叶风
 * Qq:    355007778
 * Email: ye.fn@163.com
 */

namespace c\shop\order;
\lang::load('shop');

class g extends \control
{
    var $State = array(1,//待付款
        2,//待发
        3,//已发
        5,//评价
		6,//ok
        11, //退货
        0//关闭
        );
	var $table = 'shop_order';
	
    function payWay($b=null)
    {
        $a = include CONFIG_DIR . 'shop-payWay.php';
        
        if ($b===null)
         {
			$aa = array();
            foreach ($a as $k=>$v)
             {
                if ($v['state']>0)
                    $aa[]=array('id'=>$k, 'name'=>$v['name']);
             }
			return $aa;
         }
        elseif (isset($a[$b]))
         {
            $a = $a[$b];
            if ($a['state']>0)
                return $a;                
         }
        return false;
    }
    
    function flow($id, $txt, $b='Customer')
    {
        $this->db->save('shop_flow', array('order_id'=>$id, 'user_name'=>\lang::g($b), 'note'=>$txt));
    }
    
    //支付成功后续操作
    function paid($data)
    {
        $this->db->save($this->table, array('state'=>2, 'pay_sn'=>$data['pay_sn']), 'id='. $data['id']);
        if ($this->db->num_affected()>0)
         {
            $this->flow($data['id'], \lang::g('Paid.'));
            return TRUE;
         }
    }
	
	//收货后操作
	function complete($id)
	{
		$this->db->save($this->table, array('state'=>5), 'id='. $id . ' AND state=3');
		if ($this->db->num_affected()>0)
		 {
						
			return true;
		 }
		return false;
	}
	//评价完成交易
	function ok($id)
	{
		$this->db->save('shop_order', array('state'=>6), 'id='. $id);

	}
}